cd $env(POLYN)



set p [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" {nios2-flash-programmer} \
        --epcs --base 9800 --instance 1 --go \
        --read ./fw/tmp/cfg.bin --read-bytes 0x600000+2048 \
]
set p [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" {flash2dat} \
        --infile=./fw/tmp/cfg.bin --outfile=./fw/tmp/cfg.dat --width=8 --base=0x600000 --end=0x600800 \
]

set file [open ./fw/tmp/cfg.dat r]
set r [read $file]
close $file
set r [split $r "\n"]
set yy ""
foreach j $r {
    set yy $yy[format "%c" 0x0[lindex $j 1]]
}

set t [exec "$env(SOPC_KIT_NIOS2)\\Nios II Command Shell" find ./fw/tmp/ -type f -delete]

regsub changeset: $yy "" y2
set rev [lindex [split $y2 :] 0]
set t [exec hg update --config ui.merge=internal:fail --rev $rev --clean]

exit
